/**
 * Dynamo Application Engine
 * Object Framework
 *
 * Author:
 * Sean Micklethwaite
 **/

#ifndef __dyapp_rt_objectH__
#define __dyapp_rt_objectH__

#include "mm.h"
#include "string.h"

namespace Runtime {
	class Object: public GcObject {
	public:
		/// Storage for the object's property table.
		class Members {
			/// Generic object member
			struct Entry {
				Entry * pChainLink;

				virtual const void * getValue() const = 0;
				virtual void setValue(const void * pValue) = 0;
			};

			/// A reference to an object
			struct ObjectEntry: public Entry {
				Object::tRef Ref;

				const void * getValue() const {
					return (const void *)&Ref;
				};
				void setValue(const void * pValue) {
					Ref = *(Object::tRef*)pValue;
				};
			};

			/// Defines an object member as a primitive value type exported by the
			/// runtime.
			template <class T>
			struct PrimitiveEntry: public Entry {
				T Value;

				const void * getValue() const {
					return (const void *)&Value;
				};
				void setValue(const void * pValue) {
					Value = *(const T*)pValue;
				};
			};

			typedef std::map<StringPool::Entry, Object::tRef> tStorage;

		};

	private:
		/// Object properties
		Members mvMembers;

	public:
		Property& getMember(const StringPool::Entry& sName);
		void setMember(const StringPool::Entry& sName, const Property& m);

		virtual bool isPure() const;
	};
};

#endif
